#ifndef VSIKCONTROLLER_H
#define VSIKCONTROLLER_H
#include "VSAnimBaseFunction.h"
#include "VSBoneNode.h"
namespace VSEngine2
{
	class VSStream;
	class VSGRAPHIC_API VSIKController : public VSAnimBaseFunction
	{
		//RTTI
		DECLARE_RTTI;
		//PRIORITY
		
	public:
		virtual ~VSIKController();
		virtual bool UpdateEx(double dAppTime);

		VSIKController(const VSUsedName & ShowName,VSAnimTree * pAnimTree);

		VSREAL m_fTargetThreshold;

		unsigned int m_uiIterations;

		bool m_bOrderRToE;
		bool m_bAllowTranslation;
		bool m_bAllowRotation;

		void SetRootBoneName(const VSString & RootBoneName);
	protected:
		VSIKController();
		VSREAL GetCurError()const;
		VSString m_RootBoneName;
		VSArray<VSBoneNode*> m_pIKNode;
		VSArray<VSBoneNode*> m_pEffector; 
		
		void UpdateLocalTranslation(VSBoneNode * pIKBone,double dAppTime);
		void UpdateLocalRotation(VSBoneNode * pIKBone,double dAppTime);
	public:
		static bool RegisterMainFactory();
		
		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
		virtual bool Link(VSStream & rStream);

		virtual bool Register(VSStream & rStream)const;
	private:
		static bool InitialClassFactory();	
		static VSObject * FactoryFunc();
		static bool ms_bRegisterMainFactory;
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);

	};
	typedef VSPointer<VSIKController> VSIKControllerPtr;
}
#endif